package com.atguigu.gulimall.product.bn.controller;

import org.springframework.web.util.UriUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @NAME: test
 * @USER: wjj
 * @DATE: 2023/5/22
 * @TIME: 11:40
 * @DAY_NAME_FULL: 星期一
 * @PROJECT_NAME: SpringMVC
 */
public class test {
    public static void main(String[] args) throws UnsupportedEncodingException {
//        test test = new test();
//        System.out.println(test.dealResult1(""));
//        System.out.println(new Date().getTime());
//        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        //格式化
//        String format1 = sdf1.format(new Date());
//        System.out.println(format1);
//
//        String ss="{\"corp_id\":\"16765422019805714\",\"appid\":\"16765422019806212\",\"event_type\":\"chat_toolbar\",\"timestamp\":\"1685087969\",\"event\":{\"operator_account\":\"bs8\",\"operator_uid\":\"16765422019805725\",\"chat_id\":\"16765422019805907\",\"chat_type\":\"group\"}}";
//        String s1="event_type\":\"";
//        System.out.println(s1.contains("eve"));
//        System.out.println(ss.substring(ss.indexOf(s1)+s1.length(), ss.indexOf("\",\"timestamp")));
//
//        println("++++++++++++++++颜色++++++++++++++++++++");
       
//        String sss="sa76TnKW3DzJ2lbZNTz9GrciHwBl49TDXOpPEXRKc1YuvBTZKFm7s3I2iBM2kHAG/vSYpl H3GzWtSR7mjlwq4q5yD/tkl3yD7Ui71fMdJY=";
//        String replace = sss.replace(" ", "+");
//        System.out.println(replace);
        String encode = URLEncoder.encode("sa76TnKW3DzJ2lbZNTz9GrciHwBl49TDXOpPEXRKc1YuvBTZKFm7s3I2iBM2kHAG/vSYpl+H3GzWtSR7mjlwq4q5yD/tkl3yD7Ui71fMdJY=");
        System.out.println(encode);
        System.out.println(UriUtils.decode("tOntBulT3xWPw+dbbT5ZJ43QzMJP4ZBmV9jQmiH+bgUpQ1v9CXQTml34+T1PX1gd6nDqIp6+sNQN0c9dSruVood2DUd16aUL3rw086jzdM27BnIopsZAJOE7D9baFUyTPbewIf9xyVAjZLJ6OK9i/KcPGaECi5k5mJi9J+7YXXk","utf-8"));
        System.out.println(URLDecoder.decode("tOntBulT3xWPw+dbbT5ZJ43QzMJP4ZBmV9jQmiH+bgUpQ1v9CXQTml34+T1PX1gd6nDqIp6+sNQN0c9dSruVood2DUd16aUL3rw086jzdM2Y9eaSZOjyzkdfA0tZ6FzpbN02vjPcvq3Kh/QN7DH/VBuCBAMJ8DMVtKtAkLtzrXE","utf-8"));
//        String s = unicodeDecode("{\"corp_id\":\"16800606391895106\",\"appid\":\"16800606391895217\",\"event_type\":\"slash_command_click\",\"timestamp\":\"1690368854\",\"event\":{\"operator_account\":\"bn8\",\"operator_uid\":\"16800606391895213\",\"chat_id\":\"16800606391895215\",\"chat_type\":\"group\",\"message_id\":\"7260078950821399638\",\"message_text\":\"\\/\\u672c\\u8111\\u63d0\\u793a \"}}");
//        System.out.println(s.contains("提示"));
//
//        System.out.println(UUID.randomUUID().toString());
//        String ss=null;
//        System.out.println(ss.equals("1"));

    }

    public void onCallback() {
        ExecutorService executor = Executors.newCachedThreadPool();
        executor.execute(() -> {
            try {
                Thread.sleep(1000 * 10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 这边执行具体的方法
            this.syncDealResult();

        });
        executor.shutdown();
    }

    public String dealResult(String params) {
        // 先返回结果，然后异步执行
        this.onCallback();

        return "result";
    }

    public String dealResult1(String params) {
        // 先返回结果，然后异步执行
        ExecutorService executor = Executors.newCachedThreadPool();
        executor.execute(() -> {
            try {
                Thread.sleep(1000 * 10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 这边执行具体的方法
            System.out.println("方法");

        });
        executor.shutdown();

        return "result";
    }


    public void syncDealResult() {

        try {
            System.out.println("方法");
            // 具体操作
        } catch (Exception e) {
            e.printStackTrace();

        }

        // 推送结果
    }
    public static void println(Object object)
    {
//        System.out.println("\033[40;31;4m" + object.toString() + "\033[0m");
//     其他颜色。。
//        System.out.println("\033[30;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[31;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[32;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[33;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[34;4m" + object.toString() + "\033[0m");
        System.out.println("\033[35;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[36;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[37;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[40;31;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[41;32;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[42;33;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[43;34;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[44;35;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[45;36;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[46;37;4m" + object.toString() + "\033[0m");
//        System.out.println("\033[47;4m" + object.toString() + "\033[0m");
    }
    public static String unicodeEncode(String string) {
        char[] utfBytes = string.toCharArray();
        String unicodeBytes = "";
        for (int i = 0; i < utfBytes.length; i++) {
            String hexB = Integer.toHexString(utfBytes[i]);
            if (hexB.length() <= 2) {
                hexB = "00" + hexB;
            }
            unicodeBytes = unicodeBytes + "\\u" + hexB;
        }
        return unicodeBytes;
    }
    public static String unicodeDecode(String string) {
        Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
        Matcher matcher = pattern.matcher(string);
        char ch;
        while (matcher.find()) {
            ch = (char) Integer.parseInt(matcher.group(2), 16);
            string = string.replace(matcher.group(1), ch + "");
        }
        return string;
    }

}
